package com.passive.lock.service.log.imp;

import java.util.LinkedList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.passive.lock.mapper.TDeviceLogMapper;
import com.passive.lock.mapper.TDeviceLogMapperCustom;
import com.passive.lock.model.po.TDeviceLog;
import com.passive.lock.model.vo.TDeviceLogVo;
import com.passive.lock.model.vo.TSysLogVo;
import com.passive.lock.service.log.DeviceLogService;
import com.passive.lock.utils.DateUtils;
import com.passive.lock.utils.DozerMapperUtils;
import com.passive.lock.utils.Result;

@Service("deviceLogService")
public class DeviceLogServiceImpl implements DeviceLogService {

	@Resource(name = "TDeviceLogMapperCustom")
	private TDeviceLogMapperCustom deviceLogMapperCustom;

	@Resource(name = "TDeviceLogMapper")
	private TDeviceLogMapper deviceLogMapper;

	@Override
	public List<TDeviceLogVo> deviceLogList(String groupid, long beginTime, long endTime, String logType,
			String username, String lockname, String keyname, int offset, Integer limit) throws Exception {
		List<TDeviceLogVo> list = deviceLogMapperCustom.deviceLogList(beginTime, endTime, groupid, logType, username,
				lockname, keyname, offset, limit);
		for (TDeviceLogVo tdeviceLogVo : list) {
			tdeviceLogVo.setDevicelogtime(DateUtils.unixTimestampToDate(tdeviceLogVo.getLogtime()));
			tdeviceLogVo.setDeviceuploadtime(DateUtils.unixTimestampToDate(tdeviceLogVo.getUploadtime()));
		}
		return list;
	}

	@Override
	public int deviceLogListCount(String groupid, long beginTime, long endTime, String logType, String username,
			String lockname, String keyname) throws Exception {
		return deviceLogMapperCustom.deviceLogListCount(beginTime, endTime, groupid, logType, username, lockname,
				keyname);
	}

	@Override
	public Result deviceLogUpload(TDeviceLogVo deviceLogVo) {
		TDeviceLog deviceLog = new TDeviceLog();
		DozerMapperUtils.map(deviceLogVo, deviceLog);
		deviceLogMapper.insert(deviceLog);
		return null;
	}

}
